/**
 * Created by Administrator on 2017/7/16.
 */
var React = require('react');
var ajax = require('../tools/ajax');
var Icon = require('../components/Icon');

module.exports = React.createClass({
    getInitialState: function (){
        return {
            show:false,
            address:"",
            data:[{name:"跨樂購",add:"杭州市"},{name:"跨樂購",add:"杭州市"},{name:"跨樂購",add:"杭州市"}],
            flag:false,
        }
    },
    componentDidMount: function () {
        this.Obtain();
    },
    ckClose:function () {
      this.setState({show:false})
    },
    Obtain:function(){
        var p=this;
        ajax("POST","dingwei",{},function(dt) {
            if (dt && dt.success) {
                console.log(dt);
                p.setState({data:dt.data});
            }
        });

    },
    dianpu:function (e) {
        var shopid = e.currentTarget.getAttribute('data-id');
        var country = e.currentTarget.getAttribute('data-country');
        var flag = this.state.flag;
        if(shopid && shopid !="null"){
            if(flag){
                this.setState({flag:false});
            }
            localStorage.setItem("shopId",shopid);
            this.ckClose();
            this.props.action();
        }
    },
    render: function () {
        var p=this;
        var datStr = this.state.data.map(function (d,index) {
           return(
                <div key={index} className="tanChuan-scrollOne" onClick={p.dianpu} data-country={d.address} data-id={d.id}>
                    <p>{d.shopname}</p>
                    <p>{d.address}</p>
                </div>
           )
        });
        return (
            <div className="mai" id="mai" style={{display: p.state.show? "block":"none"}}>
                <div id="tanChuan"></div>
               <div id="tanChuan-text">
                   <div id="tanChuan-get">
                       <Icon icon="#icon-dingwei1"></Icon>
                       <div className="fl shopDian">
                           <p className="shopNum">附近店铺</p>
                           <p className="shopDing">手动选择门店进行定位</p>
                       </div>
                       <span className="span" onClick={p.ckClose}></span>
                       <Icon icon="#icon-chuyidong"></Icon>
                   </div>
                   <div id="tanChuan-scroll">
                       {datStr}
                   </div>
               </div>
            </div>
        )
    }
});